package com.centronix.web;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import org.primefaces.event.SelectEvent;

import com.centronix.bean.ComboBean;
import com.centronix.domain.ProductRelease;
import com.centronix.domain.Stock;
import com.centronix.manager.EmployeeManager;
import com.centronix.manager.ProductReleaseManager;
import com.centronix.manager.StockManager;
import com.centronix.web.util.DateTimeUtil;

@ManagedBean(name = "productReleaseBean")
@SessionScoped
public class ProductReleaseBean {
	
	private List<ComboBean> employeeComboList = new ArrayList<ComboBean>(0);
	private List<ProductRelease> productReleaseList = new ArrayList<ProductRelease>(0);
	private List<Stock> stockList = new ArrayList<Stock>(0);
	
	@ManagedProperty("#{employeeManager}")
	private EmployeeManager employeeManager;
	
	@ManagedProperty("#{productReleaseManager}")
	private ProductReleaseManager productReleaseManager;
	
	@ManagedProperty("#{stockManager}")
	private StockManager stockManager;
	
	private String selectedEmployee = "";
	
	private ComboBean selectedProductAutoComplete;
	
	private boolean dataVisible = false;
	
	private Date selectedDate = new Date();
	
	public List<ComboBean> completeProduct(String query) {  
        return productReleaseManager.getProductsByType(query);  
    }
	
	public String openProductRelease(){
		employeeComboList = employeeManager.getEmployeeCombo();
		return "productrelease";
	}
	public void handleProductSelect(SelectEvent event) {  
	    FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Selected:", null);  
	    FacesContext.getCurrentInstance().addMessage(null, message);
	    System.out.println("Hello ");
	}  
	public void loadReleasedProductToEmployee(){
		//stockList = stockManager.findAllStock();
		
		if(selectedEmployee != null && selectedEmployee.length() > 0){
			
			productReleaseList = productReleaseManager.getProductsReleasedToEmployee(Integer.valueOf(selectedEmployee), DateTimeUtil.removeTimeFromDate(selectedDate));
			if(productReleaseList != null && !productReleaseList.isEmpty()){
				dataVisible = true;
			}else{
				dataVisible = false;
			}
		}else{
			productReleaseList.clear();
			dataVisible = false;
		}
	}

	public List<ComboBean> getEmployeeComboList() {
		return employeeComboList;
	}

	public void setEmployeeComboList(List<ComboBean> employeeComboList) {
		this.employeeComboList = employeeComboList;
	}

	public EmployeeManager getEmployeeManager() {
		return employeeManager;
	}

	public void setEmployeeManager(EmployeeManager employeeManager) {
		this.employeeManager = employeeManager;
	}

	public ProductReleaseManager getProductReleaseManager() {
		return productReleaseManager;
	}

	public void setProductReleaseManager(ProductReleaseManager productReleaseManager) {
		this.productReleaseManager = productReleaseManager;
	}

	public String getSelectedEmployee() {
		return selectedEmployee;
	}

	public void setSelectedEmployee(String selectedEmployee) {
		this.selectedEmployee = selectedEmployee;
	}

	public boolean isDataVisible() {
		return dataVisible;
	}

	public void setDataVisible(boolean dataVisible) {
		this.dataVisible = dataVisible;
	}

	public Date getSelectedDate() {
		return selectedDate;
	}

	public void setSelectedDate(Date selectedDate) {
		this.selectedDate = selectedDate;
	}

	public List<ProductRelease> getProductReleaseList() {
		return productReleaseList;
	}

	public void setProductReleaseList(List<ProductRelease> productReleaseList) {
		this.productReleaseList = productReleaseList;
	}

	public List<Stock> getStockList() {
		return stockList;
	}

	public void setStockList(List<Stock> stockList) {
		this.stockList = stockList;
	}

	public StockManager getStockManager() {
		return stockManager;
	}

	public void setStockManager(StockManager stockManager) {
		this.stockManager = stockManager;
	}

	public ComboBean getSelectedProductAutoComplete() {
		return selectedProductAutoComplete;
	}

	public void setSelectedProductAutoComplete(ComboBean selectedProductAutoComplete) {
		this.selectedProductAutoComplete = selectedProductAutoComplete;
	}
	
}
